package xhwl.insurance.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;

import xhwl.insurance.R;
import xhwl.insurance.http.bean.resp.TwoSaleResp;

/**
 * Created by chengang on 2017/7/10.
 */

public class My_SxjgAdapter extends BaseAdapter {
    private Context mContext;
    private ArrayList<TwoSaleResp> mlistVo;

    public My_SxjgAdapter(Context mContext, ArrayList<TwoSaleResp> mlistVo) {
        this.mContext = mContext;
        this.mlistVo = mlistVo;
    }

    @Override
    public int getCount() {
        return mlistVo.size();
    }

    @Override
    public Object getItem(int position) {
        return mlistVo.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.xsjg_item, null);
            holder = new ViewHolder();
            holder.name_tv = (TextView) convertView.findViewById(R.id.name_tv);
            holder.iphone_tv = (TextView) convertView.findViewById(R.id.iphone_tv);
            holder.time_tv = (TextView) convertView.findViewById(R.id.time_tv);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.name_tv.setText(mlistVo.get(position).getUSER_NAME());
        holder.iphone_tv.setText(getIphone(mlistVo.get(position).getLINK_MOBILE()));
        String timeTv[] = mlistVo.get(position).getCREATE_DATE().split(" ");
        holder.time_tv.setText(timeTv[0]);

        return convertView;
    }

    class ViewHolder {
        TextView name_tv;
        TextView iphone_tv;
        TextView time_tv;

    }

    private String getIphone(String pNumber) {
        String phone = "";
        if (!"".equals(pNumber) && pNumber.length() > 6){
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < pNumber.length(); i++) {
                char c = pNumber.charAt(i);
                if (i >= 3 && i <= 6) {
                    sb.append('*');
                } else {
                    sb.append(c);
                }
            }
            phone = sb.toString().trim();

        }

        return phone;
    }
}
